package com.example.daiyinuo.proxy;

public class Client {
    public static void main(String[] args) {
        TeacherDao teacherDao = new TeacherDao();
        //静态代理
        //TeacherDaoProxy teacherDaoProxy = new TeacherDaoProxy(teacherDao);
        //teacherDaoProxy.teach();
        //动态代理
        //创建目标对象
        ITeacherDao target = new TeacherDao();
        //给目标对象，创建代理对象,可以转为ITeacherDao
        ITeacherDao proxyInstance = (ITeacherDao) new ProxyFactory(target).getProxyInstance();
        //class com.sun.proxy.$Proxy0 内存中动态生成了代理对象
        System.out.println("proxyInstance==" + proxyInstance.getClass());
        proxyInstance.sayHello("DXX");
        StudentDao targetStudent = new StudentDao();
        StudentDao proxyInstanceStudent = (StudentDao) new ProxyFactoryStudent(
                targetStudent).getProxyInstance();
        String mane = proxyInstanceStudent.study();
        System.out.println("cglib代理模式"+mane);
    }
}
